package com.p2p.service.operationsManagementService.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.p2p.common.DTO.ExperienceRecordDTO;
import com.p2p.common.base.RespResult;
import com.p2p.common.base.RespResultCode;
import com.p2p.mapper.ExperienceRecordMapper;
import com.p2p.service.operationsManagementService.ExperienceRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class ExperienceRecordServiceImpl implements ExperienceRecordService {

    @Autowired
    private ExperienceRecordMapper experienceRecordMapper;

    @Override
    public RespResult experienceRecordList(Integer currentPage, Integer pageSize) {
        if(currentPage != null && pageSize != null){
            Page<ExperienceRecordDTO> page = new Page(currentPage,pageSize);
            List<ExperienceRecordDTO> experienceRecordDTOS = experienceRecordMapper.experienceRecordList(page);
            Map<String,Object> map = new HashMap();
            map.put("experienceRecordDTOS",experienceRecordDTOS);
            map.put("page",page);
            return RespResult.success(map);
        }
        return RespResult.error(RespResultCode.ERR_PARAM_NOT_LEGAL.getCode(),RespResultCode.ERR_PARAM_NOT_LEGAL.getMessage(),null);
    }

    @Override
    public RespResult search(ExperienceRecordDTO experienceRecordDTO,Integer currentPage,Integer pageSize) {
            if (currentPage != null && pageSize != null){
                Page<ExperienceRecordDTO> page = new Page<>(currentPage,pageSize);
                String investorsName = experienceRecordDTO.getInvestorsName();
                String phoneNum = experienceRecordDTO.getPhoneNum();
                String userSource = experienceRecordDTO.getUserSource();
                Byte status = experienceRecordDTO.getStatus();
                List<ExperienceRecordDTO> search = experienceRecordMapper.search(page,investorsName,phoneNum,userSource,status);
                Map<String,Object> map = new HashMap();
                map.put("search",search);
                map.put("page",page);
                return RespResult.success(map);
            }
        return RespResult.error(RespResultCode.ERR_PARAM_NOT_LEGAL.getCode(),RespResultCode.ERR_PARAM_NOT_LEGAL.getMessage(),null);
    }
}
